//
//  YHMainViewController.swift
//  YHWeibo
//
//  Created by yuhao.mac on 16/6/23.
//  Copyright © 2016年 yuhao.mac. All rights reserved.
//

import UIKit

class YHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //自定义tabBar
        let tabBar = YHTabBar()
        
        tabBar.yhDelegate = self
        
//        self.tabBar = tabBar
        //通过KVC给只读属性赋值
        setValue(tabBar, forKey: "tabBar")
        
        addChildViewController(YHHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(YHMessageViewController(), title: "消息", imgName: "tabbar_message_center")
        addChildViewController(YHDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(YHProfileViewController(), title: "我", imgName: "tabbar_profile")
    }
    
    func addChildViewController(vc: UIViewController,title: String,imgName: String) {
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imgName)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")
        
        let navC = UINavigationController(rootViewController: vc)
        addChildViewController(navC)
        
    }

}

extension YHMainViewController:YHTabBarDelegate{

    func composeButtonClick() {
        let nav = UINavigationController(rootViewController: YHComposeViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
